package controller

import (
	"github.com/gin-gonic/gin"
	"root/model"
	"root/utility"
	"strconv"
)

type ListData struct {
	List []model.UserCoinRecord `json:"list"`
	Total int `json:"total"`
}

func GetShareList(c *gin.Context)  {
	var list ListData
	var ucr model.UserCoinRecord
	uid := c.GetInt("uid")
	page ,err := strconv.Atoi(c.PostForm("page"))
	if err != nil {
		SendResponse(c,400,"",err)
		return
	}
	pageSize ,err:= strconv.Atoi(c.PostForm("pageSize"))
	if err != nil {
		SendResponse(c,400,"",err)
		return
	}

	db := utility.GetDb()
	db.Debug().Where("uid = ? ",uid).Select("id,uid,distribute,target_id").Limit(pageSize).Offset((page - 1 )* pageSize).Preload("UserInfo").Find(&list.List)
	//db.Debug().Find(&list.List)
	db.Model(&ucr).Where("uid = ? ",uid).Count(&list.Total)

	SendResponse(c,200,"",list)
}
